﻿using UnityEngine;
using System.Collections;
using DragonBones;

public class CameraFollow : MonoBehaviour {
	public UnityEngine.Transform FollowTarget;
	public float FowardDist=3;
	public float MoveSpeed = 3;
	public bool m_isLimitMoveLeft = false;
	private Vector2 targetPos;
	private Vector2 selfPos;
	private Vector2 result;
	// Use this for initialization
	void Start () {
	
	}

	// Update is called once per frame
	void LateUpdate () {
		//Debug.Log ("camera move before:"+transform.position);
		targetPos = new Vector2(FollowTarget.position.x+FowardDist, FollowTarget.position.y);
		selfPos = new Vector2(transform.position.x, transform.position.y);
		if(m_isLimitMoveLeft && FollowTarget.position.x - transform.position.x < 0)
		{
			targetPos = new Vector2(transform.position.x, FollowTarget.position.y);
		}

		result = Vector2.Lerp (selfPos, targetPos, MoveSpeed*Time.deltaTime);
		transform.position = new Vector3(result.x, result.y, transform.position.z);
		//Debug.Log ("camera move after:"+transform.position);
	}
}
